package cn.chenfeifx.example.examples;

import cn.chenfeifx.core.common.FxUtil;
import cn.chenfeifx.core.controls.CFCarousel;
import cn.chenfeifx.core.controls.CFImage;
import javafx.collections.FXCollections;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

public class DataExample extends StackPane {

    private final VBox vBox = new VBox();

    public DataExample() {
        getChildren().add(vBox);
        vBox.setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
        vBox.setSpacing(50);
        vBox.setAlignment(Pos.CENTER);

        // 头像组件
        Image avatarImage = FxUtil.getImage("/img/avatar.png");
        //
        HBox hBox = new HBox();
        hBox.setAlignment(Pos.CENTER);
        hBox.setSpacing(20);
        for (CFImage.Fit value : CFImage.Fit.values()) {
            hBox.getChildren().add(getCFImageViewBox(value));
        }

        // 轮播图
        CFCarousel cfCarousel = new CFCarousel(
                FXCollections.observableArrayList(
                        new ImageView(FxUtil.getImage("/img/img1.png")),
                        new ImageView(FxUtil.getImage("/img/img2.png")),
                        new ImageView(FxUtil.getImage("/img/img3.png")),
                        new ImageView(FxUtil.getImage("/img/img4.png")),
                        new ImageView(FxUtil.getImage("/img/img5.png"))
                ));

        //
        vBox.getChildren().addAll(hBox, cfCarousel);

    }

    public VBox getCFImageViewBox(CFImage.Fit fit) {
        CFImage cfImage = new CFImage("https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg", 100, 100, 10);
        cfImage.setStyle("-fx-background-color:rgba(0,0,0,0.05);");
        cfImage.setFit(fit);
        //
        VBox vBox = new VBox(cfImage, new Label(fit.name().toLowerCase().replaceAll("_", "-")));
        vBox.setAlignment(Pos.CENTER);
        vBox.setSpacing(10);
        vBox.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
        return vBox;
    }

}
